package com.example.telephoneBook;

import android.content.Context;
import android.content.Intent;
import android.view.ActionProvider;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;

public class PlusActionProvider extends ActionProvider {

    private Context context;

    /**
     * Creates a new instance. ActionProvider classes should always implement a
     * constructor that takes a single Context parameter for inflating from menu XML.
     *
     * @param context Context for accessing resources.
     */
    public PlusActionProvider(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public View onCreateActionView() {
        return null;
    }

    @Override
    public void onPrepareSubMenu(SubMenu subMenu) {
        subMenu.clear();
        subMenu.add("我").setIcon(R.drawable.ic_launcher).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
            	// 跳转
            	context.startActivity(new Intent(context,MiActivity.class));
                return true;
            }
        });
        subMenu.add("设置").setIcon(R.drawable.ic_launcher).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
            	// 跳转
            	context.startActivity(new Intent(context,CIActivity.class));
            	
                return true;
            }
        });
        subMenu.add("关于我们").setIcon(R.drawable.ic_launcher).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
            	// 跳转
            	context.startActivity(new Intent(context,AbuoutActivity.class));
                return true;
            }
        });
        

    }

    @Override
    public boolean hasSubMenu() {
        return true;
    }
}
